# !/usr/bin/python
# _*_ coding:UTF-8 _*_

import adaboost as ada
import numpy as np


def test_build_stump():
    (data, class_label) = ada.load_simp_data()
    D = np.mat(np.ones((5, 1)) / 5)
    (best_stump, min_error, best_class_est) = ada.build_stump(data, class_label, D)
    print best_stump
    print min_error
    print best_class_est
    ada.vist_class_result(data, class_label, best_stump)


def test_adaboost():
    (data, class_label) = ada.load_simp_data()
    weak = ada.adaboost_train(data, class_label, 9)
    print ada.ada_classify(np.mat([[5, 5], [0, 0]]), weak)


def test_visitdata():
    (data, class_label) = ada.load_simp_data()
    ada.vist_data(data, class_label)

#
def test_horse_train():
    (train_data, train_label_class) = ada.load_data_set('horseColicTraining2.txt')
    (test_data, test_label_class) = ada.load_data_set('horseColicTest2.txt')
    classifier_array = ada.adaboost_train(train_data, train_label_class, 50)
    prediction = ada.ada_classify(test_data, classifier_array)

    error = np.mat(np.ones((67, 1)))

    error_num = error[prediction != test_label_class].sum()
    print error_num/67.0



# def test
if __name__ == "__main__":
    test_horse_train()